﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SnmpForm.DbWrapper
{
    class ExcleDataOperate
    {
       //使用单件模式
        static ExcleDataOperate _instance = null;
        public static ExcleDataOperate Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ExcleDataOperate();
                }
                return _instance;
            }
        }

        private ExcelHelper _mgr;

        public ExcleDataOperate()
        {
            _mgr = new ExcelHelper();
        }

        ~ExcleDataOperate()
        {
            if (_mgr != null)
            {
                _mgr.Dispose();
            }
        }

        public bool APListTemplateExport()
        {
            _mgr.ListToExcelSaved(null, DbDataTypes.ExcleTemplate.DBTableColunm, DbDataTypes.ExcleTemplate.ExcleTableColunm);
            _mgr.Dispose();
            return true;
        }

        public int APListImport()
        {//excel进程关闭有问题
            int count = -1;
            List<object> list = null;
            list = _mgr.ReadExcleToList(DbDataTypes.ExcleTemplate.DBTableColunm);
            if(list != null)
                count = DbWrapper.SQLDataOperate.Instance.SaveAPInfoList(list);
            _mgr.Dispose();
            return count;
        }

        public bool APListExport(int _uid,string _floorid)
        {
            List<object> list = null;
            bool ret = true;
            list = DbWrapper.SQLDataOperate.Instance.GetApInfoList(_uid,_floorid);
            if (list == null)
                return false;
            ret = _mgr.ListToExcelSaved(list, DbDataTypes.ExcleTemplate.DBTableColunm, DbDataTypes.ExcleTemplate.ExcleTableColunm);
            _mgr.Dispose();
            return true;
        }
    }
}
